package com.zklh.leetcode.top100;

import com.zklh.leetcode.constructor.lru.Node;

import java.util.*;

/**
 * 最小栈算法实现
 *
 * @version 1.0
 * @Author tongnan
 * @Date 2023/11/24
 */
public class Solution155 {

    static class MinStack {

        Deque<Integer> minDeque;
        Deque<Integer> deque;

        public MinStack() {
            minDeque = new LinkedList<>();
            deque = new LinkedList<>();
        }

        public void push(int val) {
            deque.push(val);
            minDeque.push(minDeque.isEmpty() ? val : Math.min(minDeque.peek(), val));
        }

        public void pop() {
            deque.pop();
            minDeque.poll();
        }

        public int top() {
            return deque.peek();
        }

        public int getMin() {
           return minDeque.peek();
        }
    }

    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(0);
        minStack.push(-3);
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.top());
        System.out.println(minStack.getMin());
    }

}